package com.financing.platform.dao.impl;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.financing.platform.dao.IGroupDao;
import com.financing.platform.dto.GroupDTO;
import com.financing.platform.util.SqlName;

/**
 * 
* @ClassName: GroupDaoImpl 
* @Description: 组信息管理DAO 
* @author chenming 
* @date 2014年7月21日 下午3:33:49 
*
 */
@Repository("groupDaoImpl")
public class GroupDaoImpl extends BaseDaoImpl implements IGroupDao{

	@SuppressWarnings("unchecked")
	public List<GroupDTO> queryAllGroup(GroupDTO group) {
		
		try {
			return this.sqlMapClient.queryForList(SqlName.queryAllGroup,group);
		} catch (SQLException e) {
			log.error("Query all group error:",e);
			return Collections.emptyList();
		}
	}

	public int addGroup(GroupDTO group) {
		try {
			group.setGroupId((String)this.sqlMapClient.queryForObject(SqlName.queryUUID));
		     this.sqlMapClient.insert(SqlName.insertGroup,group);
		     return 1;
		} catch (SQLException e) {
			log.error("add group error:",e);
			return 0;
		}
	}

	public GroupDTO queryGroup(GroupDTO group) {
		try {
			return (GroupDTO) this.sqlMapClient.queryForObject(SqlName.queryAllGroup,group);
		} catch (SQLException e) {
			log.error("Query  group info error:",e);
			return group;
		}
	}

	public GroupDTO updateGroup(GroupDTO group) {
		try {
			this.sqlMapClient.update(SqlName.updateGroup, group);
		} catch (SQLException e) {
			this.log.error("update gorup error 1!",e);
			return null;
		}
		return group;
	}

}
